"""
数据处理
"""
import json
from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LabelOpts

r_f = open("/Users/study/python/日本.txt", "r", encoding="utf-8")
m_f = open("/Users/study/python/美国.txt", "r", encoding="utf-8")
y_f = open("/Users/study/python/印度.txt", "r", encoding="utf-8")

# 美国数据
m_data = m_f.read()
m_data = m_data.replace("jsonp_1629344292311_69436(", "")
m_data = m_data[:-2]

m_dict = json.loads(m_data)

m_trend_data = m_dict["data"][0]["trend"]
m_x_data = m_trend_data["updateDate"][:314]
m_y_data = m_trend_data["list"][0]["data"][:314]


# 日本数据
r_data = r_f.read()
r_data = r_data.replace("jsonp_1629350871167_29498(", "")
r_data = r_data[:-2]

r_dict = json.loads(r_data)

r_trend_data = r_dict["data"][0]["trend"]
r_x_data = r_trend_data["updateDate"][:314]
r_y_data = r_trend_data["list"][0]["data"][:314]


# 印度数据
y_data = y_f.read()
y_data = y_data.replace("jsonp_1629350745930_63180(", "")
y_data = y_data[:-2]

y_dict = json.loads(y_data)

y_trend_data = y_dict["data"][0]["trend"]
y_x_data = y_trend_data["updateDate"][:314]
y_y_data = y_trend_data["list"][0]["data"][:314]

# 生成图表
line = Line()

# x轴
line.add_xaxis(m_x_data)

# y轴
line.add_yaxis("美国", m_y_data, label_opts=LabelOpts(is_show=False))
line.add_yaxis("日本", r_y_data, label_opts=LabelOpts(is_show=False))
line.add_yaxis("印度", y_y_data, label_opts=LabelOpts(is_show=False))

# 全局设置
line.set_global_opts(
    title_opts=TitleOpts(title="2020年美日印确诊人数", pos_left="center", pos_bottom="1%"),

)

# 生成图表
line.render()
r_f.close()
m_f.close()
y_f.close()



